home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_218 / mandel / src / main.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  9KB  |  341 lines

  1. /*
  2.  * M A N D E L B R O T      C O N S T R U C T I O N   S E T
  3.  *
  4.  * (C) Copyright 1989 by Olaf Seibert.
  5.  * Mandel may be freely distributed. See file 'doc/Notice' for details.
  6.  *
  7.  * Main Loop, and a lot of Variables.
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #ifdef DEBUG
  13. #   include <stdio.h>
  14. #   undef STATIC
  15. #   define STATIC        /* EMPTY */
  16. #endif
  17.  
  18. #include "mandel.h"
  19.  
  20. extern int    Enable_Abort;
  21.  
  22. struct IntuitionBase *IntuitionBase;
  23. struct GfxBase *GfxBase;
  24. struct LayersBase *LayersBase;
  25.  
  26. struct TextAttr Topaz80 = {
  27.     (STRPTR) "topaz.font", TOPAZ_EIGHTY, FS_NORMAL, FPF_ROMFONT
  28. };
  29.  
  30. struct TextAttr Topaz60 = {
  31.     (STRPTR) "topaz.font", TOPAZ_SIXTY, FS_NORMAL, FPF_ROMFONT
  32. };
  33.  
  34. struct NewScreen MandelNScreen =
  35. {
  36.     0, 0, 320, 256,        /* LeftEdge, TopEdge, Width, Height */
  37.     4,                /* Depth */
  38.     2, 1,            /* DetailPen, BlockPen */
  39.     NULL,            /* viewmode LORES */
  40.     CUSTOMSCREEN,        /* type */
  41.     &Topaz80,            /* Font (default) */
  42. #ifdef IEEEDP
  43.     (UBYTE *) "DP Mandelbrot Construction Set 1.3"
  44. #else
  45.     (UBYTE *) "FFP Mandelbrot Construction Set 1.3"
  46. #endif
  47. };
  48.  
  49. struct NewWindow MainNWindow =
  50. {
  51.     0, 0, 0, 0,         /* LeftEdge, TopEdge, Width, Height */
  52.     2, 1,            /* DetailPen, BlockPen */
  53.     CLOSEWINDOW | MENUPICK | MOUSEBUTTONS | VANILLAKEY |
  54.     SIZEVERIFY /* | MENUVERIFY */ ,
  55.     WINDOWCLOSE | ACTIVATE | WINDOWSIZING | WINDOWDRAG |
  56.     WINDOWDEPTH | NOCAREREFRESH | SMART_REFRESH | GIMMEZEROZERO,
  57.     NULL,            /* FirstGadget */
  58.     NULL,            /* default CheckMark */
  59.     (UBYTE *) "Mandelbrot Construction Window", /* Title */
  60.     NULL,            /* Screen */
  61.     NULL,            /* BitMap */
  62.     60, 25,            /* MinWidth, MinHeight */
  63.     -1, -1,            /* MaxWidth, MaxHeight */
  64.     CUSTOMSCREEN        /* Screen type */
  65. };
  66.  
  67. struct BorderInfo borderinfo;
  68.  
  69. struct IntuiText PositiveText = {
  70.     AUTOFRONTPEN, AUTOBACKPEN, AUTODRAWMODE,
  71.     AUTOLEFTEDGE, AUTOTOPEDGE, NULL, (UBYTE *) "Continue", NULL
  72. },
  73.  
  74.         NegativeText = {
  75.     AUTOFRONTPEN, AUTOBACKPEN, AUTODRAWMODE,
  76.     AUTOLEFTEDGE, AUTOTOPEDGE, &Topaz60, (UBYTE *) "Cancel", NULL
  77. };
  78.  
  79. STATIC SHORT    XY1[] = {0, 0, 0, 13, 78, 13, 78, 0, 0, 0};
  80. STATIC SHORT    XY2[] = {0, 0, 0, 17, 82, 17, 82, 0, 0, 0};
  81. STATIC struct Border border[] = {
  82.     {0, 0, 2, 0, JAM1, 5, XY1, &border[1]},
  83.     {-2, -2, 3, 0, JAM1, 5, XY2, NULL}
  84. };
  85. struct Gadget    NegativeGadget = {
  86.     NULL, -100, -20, 79, 14,    /* next, LTWH */
  87.     GADGHCOMP | GRELBOTTOM | GRELRIGHT,
  88.     RELVERIFY | ENDGADGET,
  89.     BOOLGADGET | REQGADGET,
  90.     (APTR) & border[0], NULL,
  91.     &NegativeText, 0, NULL,
  92.     NEGGADGETID, NULL
  93. };
  94. struct Gadget    PositiveGadget = {
  95.     &NegativeGadget, 20, -20, 79, 14,    /* next, LTWH */
  96.     GADGHCOMP | GRELBOTTOM,
  97.     RELVERIFY | ENDGADGET,
  98.     BOOLGADGET | REQGADGET,
  99.     (APTR) & border[0], NULL,
  100.     &PositiveText, 0, NULL,
  101.     POSGADGETID, NULL
  102. };
  103.  
  104. UBYTE        PenTable[MAXDEPTH];
  105. unsigned    PenTableMode = MODULO;
  106. short        RangeWidth = 2;
  107.  
  108. struct Screen  *MandelScreen = NULL;    /* Pointer for OpenScreen return
  109.                      * value */
  110. struct Window  *MainWindow = NULL;    /* Idem for OpenWindow */
  111. struct Window  *XYwindow;    /* The X/Y window */
  112. extern struct Window *ColorWindow;    /* Palette */
  113.  
  114.  
  115. USHORT        WBWidth = 0;    /* Preferred size of our screen */
  116. USHORT        WBHeight = 0;    /* in Hires/noninterlace values */
  117.  
  118. int        (*DepthFunc) () = ZQuadMinC;
  119. UBYTE        FunctionNr = 0;
  120.  
  121. void        (*IPlotFunc) () = None;
  122. UBYTE        IPlotNr = 0;
  123.  
  124. void        (*EPlotFunc) () = PlotIterationCount;
  125. UBYTE        EPlotNr = 0;
  126.  
  127. double        LeftEdge = -0.800,    /* Left edge of the picture */
  128.         RightEdge = 2.100,
  129.         TopEdge = 1.200,
  130.         BottomEdge = -1.200;
  131.  
  132. double        CXStep,     /* Stepsize through the complex plane */
  133.         CYStep;
  134. int        PixelStep = 1,    /* Stepsize on the screen */
  135.         MaxDepth = 100; /* Maximum iteration count */
  136.  
  137. int NumColors;            /* Number of colors on the screen */
  138.  
  139. unsigned short    FrameX1,
  140.         FrameX2,
  141.         FrameY1,
  142.         FrameY2;
  143.  
  144. short        MouseStatus = NOTFRAMING;    /* Where we are in the
  145.                          * process of selecting a
  146.                          * frame */
  147.  
  148. bool        finished = FALSE;    /* TRUE to stop the program */
  149. bool        Saved = TRUE;    /* Indicates the picture has been SAVEd */
  150. bool        NameValid = FALSE;    /* Indicates the file name is
  151.                      * valid */
  152. bool        StillDrawing = FALSE;    /* Are we still drawing ? */
  153.  
  154. FILE           *BatchFILE;    /* Current batch file */
  155. int        DrawSigBit = -1;/* Signal when drawing is finished */
  156. long        DrawSigMask;
  157.  
  158. #ifdef AREXX
  159.  
  160. /*
  161.  *  And here is some AREXX stuff. Not very complicated, thanks to
  162.  *  MinRexx by Tomas Rokicki (Radical Eye Software).
  163.  */
  164.  
  165. long        RexxMask;    /* Wait signal mask */
  166. extern short    BatchWaiting;    /* Halting all Arexx traffic as well */
  167.  
  168. #endif
  169.  
  170. /*
  171.  * M A I N   E N T R Y     P O I N T
  172.  */
  173.  
  174. main(argc, argv)
  175. int        argc;
  176. char          **argv;
  177. {
  178.     char       *Main();
  179.     extern struct SignalSemaphore DrawSemaphore;
  180.  
  181.     /*
  182.      * Before we do anything, do an operation which requires the floating
  183.      * point library. So if it is not available, we abort before we need
  184.      * to clean up anything. Note that CXStep is not initialized at this
  185.      * moment.
  186.      */
  187.  
  188.     CXStep = 1.0;
  189.     CXStep = CXStep * 2.0;
  190.  
  191.     /*
  192.      * Make sure we aren't interrupted by any user pressing ^C while we
  193.      * are doing I/O.
  194.      */
  195.     Enable_Abort = 0;
  196.  
  197.     /*
  198.      * Open each of the libraries and check for a NULL return, which
  199.      * indicates unavailability.
  200.      */
  201.  
  202.     IntuitionBase = (struct IntuitionBase *)
  203.     OpenLibrary("intuition.library", LIBRARY_VERSION);
  204.     if (IntuitionBase == NULL)
  205.     MyExit("Can't open Intuition V1.2 or newer!");
  206.  
  207.     GfxBase = (struct GfxBase *)
  208.     OpenLibrary("graphics.library", LIBRARY_VERSION);
  209.     if (GfxBase == NULL)
  210.     MyExit("Can't open Gfx V1.2 or newer!");
  211.  
  212.     LayersBase = (struct LayersBase *)
  213.     OpenLibrary("layers.library", LIBRARY_VERSION);
  214.     if (LayersBase == NULL)
  215.     MyExit("Can't open Layers V1.2 or newer!");
  216.  
  217.     DrawSigBit = AllocSignal(-1L);
  218.     if (DrawSigBit == -1)
  219.     MyExit("Can't allocate signal!");
  220.     DrawSigMask = 1L << DrawSigBit;
  221.     InitSemaphore(&DrawSemaphore);
  222.     MandelTask = FindTask(NULL);
  223.  
  224. #ifdef AREXX
  225. /*
  226.  *   For rexx, we open up a Rexx port, and Batch() will send out
  227.  *   the first command, if there was one.
  228.  */
  229.     RexxMask = upRexxPort("MANDEL", NULL, "mand", NULL) ;
  230. #endif
  231.     if (InitDisplay((bool) FALSE))
  232.     MyExit("Can't initialise the display properly!");
  233.  
  234.     CalcCSteps();
  235.     Options(argc, argv);        /* Maybe open the batch */
  236.     Batch();                    /* Check the batch */
  237.  
  238.     MyExit(Main());
  239. }
  240.  
  241. char           *
  242. Main()
  243. {
  244.     register ULONG  Class;    /* IntuiMessage class */
  245.     register USHORT Code;    /* and Code field */
  246.     struct IntuiMessage *message;    /* Expected message pointer */
  247.     struct Window  *window;    /* window related to message */
  248.     long        signalmask;
  249.     long        signals;
  250.  
  251. #ifdef AREXX
  252. /*
  253.  *   If we're working with Rexx, we wait on the Rexx bit as well.
  254.  *   Then, we handle any Rexx messages.
  255.  */
  256.     signalmask = RexxMask | DrawSigMask |
  257.            (1L << MainWindow->UserPort->mp_SigBit);
  258. #else
  259.     signalmask = DrawSigMask | (1L << MainWindow->UserPort->mp_SigBit);
  260. #endif
  261.  
  262. again:
  263.     finished = FALSE;
  264.     while (!finished) {
  265.     /*
  266.      * Wait for message port to become not empty, and extract the
  267.      * message or, alternatively, for the drawing to finish.
  268.      */
  269.  
  270.     signals = Wait(signalmask);
  271. #ifdef AREXX
  272.     if ((signals & RexxMask) && !BatchWaiting) {
  273.         dispRexxPort();
  274.     }
  275. #endif
  276.     if (signals & DrawSigMask) {    /* drawing finished */
  277.         Batch();                    /* Check the batch */
  278. #ifdef AREXX
  279.         Signal(MandelTask, RexxMask);/* Wake up Arexx as well */
  280. #endif
  281.     }
  282.     while (message = (struct IntuiMessage *)
  283.            GetMsg(MainWindow->UserPort)) {
  284.         window = message->IDCMPWindow;
  285.  
  286.         if (window == ColorWindow) {
  287.         HandleColorWindow(message);
  288.         continue;
  289.         }
  290.  
  291.         Class = message->Class;
  292.         Code = message->Code;
  293.  
  294.         if (Class & ~(MOUSEBUTTONS | INTUITICKS)) {
  295.         ReplyMsg(message);      /* Pointer is not valid anymore */
  296.         }
  297.         switch (Class) {
  298.         case MENUPICK:
  299.         GotMenu(Code);
  300.         break;
  301.         case MOUSEBUTTONS:
  302.         case INTUITICKS:
  303.         CheckMouse(message);
  304.         ReplyMsg(message);
  305.         break;
  306.         case SIZEVERIFY:
  307.         StopFraming();  /* Fall Through to MenuVerify */
  308.         case MENUVERIFY:
  309.         break;        /* Just make sure there is no half-drawn
  310.                  * frame */
  311.         case CLOSEWINDOW:
  312.         if (window == MainWindow) {
  313.             finished = TRUE;
  314.         } else {
  315.             CloseXYwindow();
  316.         }
  317.         break;
  318.         case VANILLAKEY:
  319.         if (Code == ('Q' & 0x1F)) {     /* Ctrl-Q; don't check to
  320.                          * be sure */
  321.             skipto        finished;
  322.         }
  323.         break;
  324.         /* default: Ignore strange messages */
  325.         }            /* End Switch The Class Of The Message */
  326.     }            /* End While There Is A Message */
  327.     }                /* End While Not Finished */
  328.  
  329.     /*
  330.      * So we are finished. And, by the way, are we SURE we are finished
  331.      * alltogether ??
  332.      */
  333.  
  334.     if (!Sure()) {
  335.     backto        again;
  336.     }
  337. finished:
  338.     CleanupDisplay((bool) TRUE);
  339.     return NULL;        /* Indicate Good Exit */
  340. }                /* End of Main */
  341.